package org.springframework.prospring.ticket.web;

import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.RequestUtils;
import org.springframework.prospring.ticket.service.BoxOffice;
import org.springframework.prospring.ticket.service.EventsCalendar;
import org.springframework.prospring.ticket.service.Reservation;
import org.springframework.prospring.ticket.service.ClubManager;
import org.springframework.prospring.ticket.domain.Show;
import org.springframework.prospring.ticket.domain.Booking;
import org.springframework.prospring.ticket.domain.SeatClass;
import org.springframework.prospring.ticket.domain.Club;
import org.springframework.prospring.ticket.domain.support.PerformanceWithAvailability;
import org.springframework.prospring.ticket.domain.support.PriceBandWithAvailability;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * Controller retrieving a show from the EventsCalendar
 * to show it to the user<p>
 * Input: showId<p>
 * Model:
 * <ul>
 *  <li><code>show</code>: the show to render
 *  <li><code>performances</code>: a list of PerformancesWithAvailability
 *  <li><code>showInfoUrl</code>: the url for the show information content.
 *  <li><code>seatingPlanUrl</code>: the url for hte seating plan content.
 *  <li><code>seatClasses</code>: a list of all seating classes
 * </ul>
 */
public class DisplayClubListController extends AbstractController {

    private final static String STATIC_CONTENT_SUFFIX = ".htm";
    private final static String URL_PATH_SEPERATOR = "/";

    // the club manager service this controller uses.
    private ClubManager clubManager;


    // the name of the returned view.
    private String viewName;


    /**
     * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(
     *      javax.servlet.http.HttpServletRequest,
            javax.servlet.http.HttpServletResponse)
     */
    protected ModelAndView handleRequestInternal(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
        throws Exception {


        //long regionId = RequestUtils.getRequiredLongParameter(httpRequest, "regionId");

        Collection<Club> allClubs = clubManager.findAllClubs();

        if (logger.isDebugEnabled()) {
            for (Iterator<Club> iterator = allClubs.iterator(); iterator.hasNext();) {
                Club club =  iterator.next();
                logger.debug("Club: "+club);
            }
        }

        ModelAndView mav = new ModelAndView(viewName);
        mav.addObject("allClubs", allClubs);

        if (logger.isDebugEnabled()) {
            logger.debug("ModelAndView: "+mav.toString());
        }

        return mav;
    }

    /**
     * Sets the box office service this controller should use.
     * @param clubManager The box office service this controller should use.
     */
    public void setClubManager(ClubManager clubManager) {
        this.clubManager = clubManager;
    }

    /**
     * Sets the name of the view this controller returns.
     * @param viewName The name of the view this controller returns.
     */
    public void setViewName(String viewName) {
        this.viewName = viewName;
    }



}
